<template>
	<view class="register">
		<view class="tel">
			<input type="text" v-model="tel" focus placeholder="请输入11位手机号">
		</view>
		<view class='next' @click='goNextCode'>下一步</view>
	</view>
</template>

<script>
	import http from "@/common/api/reqeust.js";

	export default {
		data() {
			return {
				tel: '',
			}
		},
		methods: {
			// 点击下一步
			goNextCode() {
				if (!this.tel) {
					uni.showModal({
						content: '请输入手机号'
					})
				} else {
					http.request({
						url: '/user/registered',
						method: 'post',
						data: {
							phone: this.tel,
						}
					}).then((res) => {
						// 手机号存在
						if (!res.success) {
							uni.showToast({
								title: res.msg,
								icon: 'none'
							})
							return;
						} else {
							uni.navigateTo({
								url: `/pages/loginCode/loginCode?phone=${this.tel}`
							})
						}
					}).catch(() => {
						uni.showToast({
							title: '请求失败',
							icon: 'none'
						})
					})
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.register {
		padding: 0 $pd20;
		padding-top: $pd20;

		.code,
		.tel {
			border-bottom: solid 2rpx #a9a9a9;
			padding-bottom: 5rpx;
		}

		.tel {
			margin-bottom: $pd20;
		}

		.next {
			width: 100%;
			height: 80rpx;
			line-height: 80rpx;
			text-align: center;
			color: #FFFFFF;
			background-color: #49BDFB;
			border-radius: 40rpx;
		}
	}
</style>
